//
//  OtherModel.m
//  DaJiang
//
//  Created by sally on 17/1/15.
//  Copyright © 2017年 jiniu. All rights reserved.
//

#import "OtherInterface.h"
#import "OtherModel.h"

@implementation OtherModel

@end

@implementation TimeModel

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
  return YES;
}

+ (JSONKeyMapper *)keyMapper {
  return [[JSONKeyMapper alloc] initWithDictionary:@{ @"id" : @"timeid" }];
}

//选择时间接口
+ (void)queryTimeWithCompletion:(void (^)(NSMutableArray *timeList))completion {
  [self cleanLastError];

  completion_t _completion = ^(NSDictionary *resultObject, NSInteger code, NSString *description) {
    if (code == SUCCESS_RESULT) {
      NSMutableArray *retMArray = [NSMutableArray array];
      NSDictionary *listResultDic = resultObject[DicKeyList];
      if (listResultDic && ![listResultDic isKindOfClass:[NSNull class]] && listResultDic.count > 0) {
        for (id item in listResultDic) {
          TimeModel *timeModel = [[TimeModel alloc] initWithDictionary:item error:nil];
          [retMArray addObject:timeModel];
        }
      }
      completion(retMArray);

    } else {
      [self setLastError:[NSError errorWithDomain:description code:code userInfo:nil]];
      completion(nil);
    }

  };

  error_t _error = ^(NSError *error) {
    [self setLastError:error];
    completion(nil);
  };

  OtherInterface *interface = [[OtherInterface alloc] init];
  [interface queryTimeWithCompletion:_completion error:_error];
}

//学历列表接口
+ (void)queryEducationWithCompletion:(void (^)(NSMutableArray *educationList))completion {
  [self cleanLastError];

  completion_t _completion = ^(NSDictionary *resultObject, NSInteger code, NSString *description) {
    if (code == SUCCESS_RESULT) {
      NSMutableArray *retMArray = [NSMutableArray array];
      NSDictionary *listResultDic = resultObject[DicKeyList];
      if (listResultDic && ![listResultDic isKindOfClass:[NSNull class]] && listResultDic.count > 0) {
        for (id item in listResultDic) {
          TimeModel *timeModel = [[TimeModel alloc] initWithDictionary:item error:nil];
          [retMArray addObject:timeModel];
        }
      }
      completion(retMArray);

    } else {
      [self setLastError:[NSError errorWithDomain:description code:code userInfo:nil]];
      completion(nil);
    }

  };

  error_t _error = ^(NSError *error) {
    [self setLastError:error];
    completion(nil);
  };

  OtherInterface *interface = [[OtherInterface alloc] init];
  [interface queryEducationWithCompletion:_completion error:_error];
}

//年限列表接口
+ (void)queryYearWithCompletion:(void (^)(NSMutableArray *yearList))completion {
  [self cleanLastError];

  completion_t _completion = ^(NSDictionary *resultObject, NSInteger code, NSString *description) {
    if (code == SUCCESS_RESULT) {
      NSMutableArray *retMArray = [NSMutableArray array];
      NSDictionary *listResultDic = resultObject[DicKeyList];
      if (listResultDic && ![listResultDic isKindOfClass:[NSNull class]] && listResultDic.count > 0) {
        for (id item in listResultDic) {
          TimeModel *timeModel = [[TimeModel alloc] initWithDictionary:item error:nil];
          [retMArray addObject:timeModel];
        }
      }
      completion(retMArray);

    } else {
      [self setLastError:[NSError errorWithDomain:description code:code userInfo:nil]];
      completion(nil);
    }

  };

  error_t _error = ^(NSError *error) {
    [self setLastError:error];
    completion(nil);
  };

  OtherInterface *interface = [[OtherInterface alloc] init];
  [interface queryYearWithCompletion:_completion error:_error];
}

@end

@implementation TimeData

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
  return YES;
}

@end

@implementation LocModel

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
  return YES;
}

//查询省级区域接口
+ (void)queryLocWithCompletion:(void (^)(NSMutableArray *locList))completion {
  [self cleanLastError];

  completion_t _completion = ^(NSDictionary *resultObject, NSInteger code, NSString *description) {
    if (code == SUCCESS_RESULT) {
      NSMutableArray *retMArray = [NSMutableArray array];
      NSDictionary *listResultDic = resultObject[DicKeyList];
      if (listResultDic && ![listResultDic isKindOfClass:[NSNull class]] && listResultDic.count > 0) {
        for (id item in listResultDic) {
          LocModel *locModel = [[LocModel alloc] initWithDictionary:item error:nil];
          [retMArray addObject:locModel];
        }
      }
      completion(retMArray);

    } else {
      [self setLastError:[NSError errorWithDomain:description code:code userInfo:nil]];
      completion(nil);
    }

  };

  error_t _error = ^(NSError *error) {
    [self setLastError:error];
    completion(nil);
  };

  OtherInterface *interface = [[OtherInterface alloc] init];
  [interface queryLocWithCompletion:_completion error:_error];
}

//查询市级区域接口
+ (void)queryCityWithLoc:(NSString *)locId
              completion:(void (^)(NSMutableArray *cityList))completion {
  [self cleanLastError];

  completion_t _completion = ^(NSDictionary *resultObject, NSInteger code, NSString *description) {
    if (code == SUCCESS_RESULT) {
      NSMutableArray *retMArray = [NSMutableArray array];
      NSDictionary *listResultDic = resultObject[DicKeyList];
      if (listResultDic && ![listResultDic isKindOfClass:[NSNull class]] && listResultDic.count > 0) {
        for (id item in listResultDic) {
          LocModel *locModel = [[LocModel alloc] initWithDictionary:item error:nil];
          [retMArray addObject:locModel];
        }
      }
      completion(retMArray);

    } else {
      [self setLastError:[NSError errorWithDomain:description code:code userInfo:nil]];
      completion(nil);
    }

  };

  error_t _error = ^(NSError *error) {
    [self setLastError:error];
    completion(nil);
  };

  OtherInterface *interface = [[OtherInterface alloc] init];
  [interface queryCityWithLoc:locId completion:_completion error:_error];
}

//查询市2级区域接口
+ (void)queryCity2WithLoc:(NSString *)locId
               completion:(void (^)(NSMutableArray *cityList))completion {
  [self cleanLastError];

  completion_t _completion = ^(NSDictionary *resultObject, NSInteger code, NSString *description) {
    if (code == SUCCESS_RESULT) {
      NSMutableArray *retMArray = [NSMutableArray array];
      NSDictionary *listResultDic = resultObject[DicKeyList];
      if (listResultDic && ![listResultDic isKindOfClass:[NSNull class]] && listResultDic.count > 0) {
        for (id item in listResultDic) {
          LocModel *locModel = [[LocModel alloc] initWithDictionary:item error:nil];
          [retMArray addObject:locModel];
        }
      }
      completion(retMArray);

    } else {
      [self setLastError:[NSError errorWithDomain:description code:code userInfo:nil]];
      completion(nil);
    }

  };

  error_t _error = ^(NSError *error) {
    [self setLastError:error];
    completion(nil);
  };

  OtherInterface *interface = [[OtherInterface alloc] init];
  [interface queryCity2WithLoc:locId completion:_completion error:_error];
}

@end
